package innerClass.anonymousInnerClass;

public class AnonymousInnerClass {
    public static void main(String[] args) {
        Outer outer = new Outer();
        outer.method();
    }
}

class Outer {
    private int n1 = 10;
    public void method() {
        //基于接口的匿名内部类
        IA tiger = new IA() {
            @Override
            public void cry() {
                System.out.println("Tiger...");
            }
        };
        
        tiger.cry();
        
        System.out.println("tiger的运行类型" + tiger.getClass().getName());

        //参数列表会传递给构造器
        Father father = new Father("jack") {
            @Override
            public void test() {
                System.out.println("匿名内部类重写的test方法");
            }


        };

        System.out.println("father运行类型" + father.getClass().getName());

        father.test();

        //基于抽象类的匿名内部类
        var dog = new Animal() {
            @Override
            void eat() {
                System.out.println("小狗吃骨头");
            }
        };

        dog.eat();
    }
}

interface IA {
    void cry();
}

class Father {
    private String name;
    public Father(String name) {
        this.name = name;
    }
    public void test() {
    }
}

abstract class Animal {
    abstract void eat();
}